package controller;

import core.BoxNode;
import core.Node;
import core.TriggerPort;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import model.codebehind.CodeModel;
import view.GUI.LabelReader;

/**
 *
 * @author Jelle, modified by Ben
 */
public class Serializer {

    private CodeModel cmodel;
    private String fileName;

    public Serializer(CodeModel cmodel, String fileName) {
        this.cmodel = cmodel;
        this.fileName = fileName;
    }

    public TriggerPort deserialize() {
        ArrayList<Node> list1 = new ArrayList<Node>();

        FileInputStream fis = null;
        ObjectInputStream in = null;
        TriggerPort mainTrigger = null;
        try {
            fis = new FileInputStream(fileName);
            in = new ObjectInputStream(fis);
            mainTrigger = (TriggerPort)in.readObject();//will be ignored
            list1 = (ArrayList<Node>) in.readObject();
            in.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        }
        cmodel.setObjects(list1);
        return mainTrigger;
    }

}